package common.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.constants.TipsConst;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.type.GoodsType;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.events.ListEvent;
	import lz.controls.managers.TipsManager;

	/**
	 * 简单球员item(球员中心样例  不包含体力 锁) 
	 * @author lake
	 * 
	 */	
	public class SimplePlayerItem extends IconItem
	{
		/**
		 * 位置 
		 */		
		public var place 		:TextField;
		/**
		 * 球员名字
		 */		
		public var playerName 	:TextField;
		/**
		 * 头像容器
		 */		
		public var contain 		:MovieClip;
		/**
		 * 名字字体 容器
		 */		
		public var fontNameCon :Sprite;
		/**
		 *参数 
		 */		
		public var param		:*;
		
		public function SimplePlayerItem()
		{
			super();
		}
		/**
		 *设置数据 
		 * @param value
		 * 
		 */		
		override public function set data(value:*):void
		{
			if(value != null && value == _data)
			{
				return;
			}
			_data = value;
			var goodsVo :GoodsVo 		= value;
			DisplayObjectUtil.removeAllChildren(contain);
			DisplayObjectUtil.removeAllChildren(fontNameCon);
			if(goodsVo)
			{
				var bitmapData :BitmapData 	= goodsVo.bitmapData;
				var bitmap :Bitmap = new Bitmap(bitmapData,"auto",true);
				contain.addChild(bitmap);
				playerName.text = goodsVo.name;
				var fontBitmapData :BitmapData = new BitmapData(playerName.width,playerName.height,true,0x00000000);
				fontBitmapData.draw(playerName,null,null,null,null,true);
				var fontBitmap :Bitmap = new Bitmap(fontBitmapData,"auto",true);
				fontNameCon.addChild(fontBitmap);
				place.text = "";
				_symbolSkin.gotoAndStop(goodsVo.color);
				addEvtListener();
			}
			else
			{
				removeEvtListener();
			}
		}
		/**
		 * 初始化
		 * @param view
		 * 
		 */		
		override public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.liangzhong.ui.playerLittleCard_S");
			this.addChild(_symbolSkin);
			place = _symbolSkin.place;
			place.text = "";
			playerName = _symbolSkin.playerName;
			playerName.text = "";
			playerName.visible = false;
			fontNameCon = new Sprite();
			fontNameCon.x = playerName.x;
			fontNameCon.y = playerName.y + 2;
			_symbolSkin.addChild(fontNameCon);
			contain = _symbolSkin.contain;
		}
		/**
		 * 添加事件
		 * 
		 */		
		override public function addEvtListener():void
		{
			this.addEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			this.addEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			this.addEventListener(MouseEvent.CLICK,onClickHandler);
			this.addEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClickHandler);
		}
		/**
		 * 移上
		 * @param e
		 * 
		 */		
		override protected function onOverHandler(e :MouseEvent):void
		{
			if(_data == null)return;
			if(_data.type == GoodsType.PLAYERCARD)
			{
				TipsManager.show(TipsConst.PLAYERCARDTIPS,_data,15,15,false,true);
			}
			else
			{
				TipsManager.show(TipsConst.BASETIPS,{tip:_data.tipsInfo},15,15,false,true);
			}
		}
		/**
		 * 移出
		 * @param e
		 * 
		 */		
		override protected function onOutHandler(e :MouseEvent):void
		{
			TipsManager.hide();
		}
		/**
		 * 点击 
		 * @param e
		 * 
		 */		
		override protected function onClickHandler(e :MouseEvent):void
		{
			if(_data == null)
			{
				return;
			}
			this.dispatchEvent(new ListEvent(ListEvent.ITEM_CLICK,true,false,-1,-1,-1,_data));
		}
		/**
		 *双击使用 
		 * @param e
		 * 
		 */		
		protected function onDoubleClickHandler(e :MouseEvent):void
		{
			
		}
		/**
		 * 删除事件
		 * 
		 */		
		override public function removeEvtListener():void
		{
			this.removeEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			this.removeEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			this.removeEventListener(MouseEvent.CLICK,onClickHandler);
			this.removeEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClickHandler);
		}
		/**
		 * 销毁
		 * 
		 */		
		override public function destroyView():void
		{
			super.destroyView();
			removeEvtListener();
			_data = null;
		}
	}
}